import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
} from '@nestjs/common';
import { UserService } from './user.service';
import { CreateUserDto } from './dto/create-user.dto';
import { UpdateUserDto } from './dto/update-user.dto';
import {
  ApiResponse,
  ApiTags,
  ApiParam,
  ApiOperation,
  ApiBearerAuth,
} from '@nestjs/swagger';
@Controller('user')
@ApiTags('user模块 ApiBearerAuth鉴权')
@ApiBearerAuth()
export class UserController {
  constructor(private readonly userService: UserService) {}

  @Post()
  create(@Body() createUserDto: CreateUserDto) {
    return this.userService.create(createUserDto);
  }

  @Get()
  findAll() {
    // return this.userService.findAll();
    return { res: '哈哈' }; //json格式
  }

  @Get(':id')
  @ApiOperation({
    summary: 'user模块',
    description: 'user Dto',
  })
  @ApiParam({ name: 'id', required: true, description: '用户id' })
  @ApiResponse({ status: 200, description: '成功', type: CreateUserDto })
  @ApiResponse({ status: 404, description: '用户不存在' })
  findOne(@Param('id') id: string): Promise<CreateUserDto> {
    // 在实际应用中，这里应该是根据 id 查询用户数据的逻辑
    // 以下为演示数据，实际中应从数据库或其他服务获取数据
    const user: CreateUserDto = {
      name: 'John Doe',
      age: 30,
      isMarried: true,
    };
    return Promise.resolve(user);
  }

  @Patch(':id')
  update(@Param('id') id: string, @Body() updateUserDto: UpdateUserDto) {
    return this.userService.update(+id, updateUserDto);
  }

  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.userService.remove(+id);
  }
}
